<template>
    <div>
        <el-row :gutter="12" type="flex">
            <el-col :span="12">
                <el-card shadow="always">
                    <template #header> <span>源分类</span> </template>
                    <kv label="组">
                        <selector url="/dev/yapi/groups" :valueIsNumber="false" v-model="source.group"
                                  fields="id,name" @change="(v,m)=> { source.project = 0; }" chk="int(0)"></selector>
                    </kv>
                    <kv label="项目">
                        <selector url="/dev/yapi/projects" v-if="$data.source.group" :valueIsNumber="false"
                                  v-model="$data.source.project"
                                  fields="id,name" @param="v=>v.groupId = $data.source.group"
                                  :key="source.group" @change="(v,m)=> { $data.source.category = 0; }" chk="int(0)"></selector>
                    </kv>
                    <kv label="分类">
                        <selector url="/dev/yapi/categories" v-if="$data.source.project" :valueIsNumber="false"
                                  v-model="$data.source.category"
                                  fields="id,name" @param="v=>v.projectId = $data.source.project"
                                  :key="$data.source.project" chk="int(0)"></selector>
                    </kv>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card shadow="always">
                    <template #header>  <span>目标分类</span> </template>

                    <kv label="组">
                        <selector url="/dev/yapi/groups" :valueIsNumber="false" v-model="target.group"
                                  fields="id,name" @change="(v,m)=> { target.project = 0; }" chk="int(0)"></selector>
                    </kv>
                    <kv label="项目">
                        <selector url="/dev/yapi/projects" v-if="target.group" :valueIsNumber="false"
                                  v-model="target.project"
                                  fields="id,name" @param="v=>v.groupId = target.group"
                                  @change="(v,m)=> { target.category = 0; }"
                                  :key="target.group" chk="int(0)"></selector>
                    </kv>
                    <kv label="分类">
                        <selector url="/dev/yapi/categories" v-if="target.project" :valueIsNumber="false"
                                  v-model="target.category"
                                  fields="id,name" @param="v=>v.projectId = target.project"
                                  :key="target.project" chk="int(0)"></selector>
                    </kv>
                </el-card>
            </el-col>
        </el-row>

        <div style="text-align: center;margin: 20px;">
            <el-button @click="move_click" type="primary">移动</el-button>
        </div>
    </div>
</template>

<script setup>
/**
 * Created by CodeGenerator at 2021-04-13 19:37:26
 */



//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({"source":{"group":0,"project":0,"category":0},"target":{"group":0,"project":0,"category":0}});

const target = $computed(()=> $data.target);

const $props = defineProps({
    sourceCatId : { type: [Number,String] }
});





const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);



const loadData = function() {
    jv.$http.post("/dev/yapi/category-info?categoryId=" + $props.sourceCatId).then(res => {
        var json = res.data.data;
        $data.source.group = json.group.id;
        $data.source.project = json.project.id;
        $data.source.category = json.category.id;
        $data.target.group = json.group.id;
        $data.target.project = json.project.id;
        $data.target.category = json.category.id;
    })
};
const move_click = function() {
    if (jv.chk_main($data) == false) {
        return;
    }
    if ($data.source.category == $data.target.category) {
        return jv.error("源与目标相同")
    }
    jv.$http.post("/dev/yapi/move", {
        sourceCategoryId: $data.source.category,
        targetCategoryId: $data.target.category
    }).then(res => {
        jv.info("移动成功")
    })
};

onMounted( function() {
    loadData();
} )



</script>
